const users = require('../mongodb/users')
const mongodb = require('../mongodb/index')

module.exports = function (){
    return (req,res,next)=>{
        // if(req.query.userid == req.session.userid){
        if(req.query.username == req.session.username){
            // mongodb.get(users,{userid:req.query.userid},data=>{
            mongodb.get(users,{username:req.query.username},data=>{
                if(data.length > 0){
                    res.send(JSON.stringify({
                        code:0,
                        msg:"获取成功",
                        data:data[0]
                    }))
                }else{
                    res.send(JSON.stringify({
                        code: 1,
                        msg: "用户信息不存在"
                    }))
                }    //这个else应该不会起作用，可以不if else
            })
        }else{
            res.send(JSON.stringify({
                code:2,
                msg:"登录信息失效"
            }))
        }
    }
}